function particle_update(timeDelta)
{
	this.time += timeDelta;
	if (this.time >= this.life)
	{
		// The particle has now exceeded its lifetime
		// It can be deactivated.
		this.active = false;
		this.time = 0;
	}
	else
		this.active = true;
	return active;
}

function particle_deactivate()
{
	this.active = false;
}

function particle_activate()
{
	this.active = true;
}

function particle_isActive()
{
	return this.active;
}

function particle_updateVelocity(accelerationX, accelerationY)
{
	this.velocityX += accelerationX;
	if (this.velocityX > 1.0)
		this.velocityX = 1.0;
	else if (this.velocityX < -1.0)
		this.velocityX = -1.0;

	this.velocityY += accelerationY;
	if (this.velocityY > 1.0)
		this.velocityY = 1.0;
	else if (this.velocityY < -1.0)
		this.velocityY = -1.0;
}

function particle()
{
	this.positionX = 0.0;
	this.positionY = 0.0;
	
	this.velocityX = 0.0;
	this.velocityY = 0.0;
	
	// The time elapsed since particle came alive.
	this.time = 0;
	
	// How long the particle can be alive.
	this.life = 0;
	
	this.active = false;
	
	// Always applied to Y axis.
	this.gravity = 0.0;
	
	this.r = 255;
	this.g = 0;
	this.b = 0;

	this.update = particle_update;
	this.updateVelocity = particle_updateVelocity;
	this.deactivate = particle_deactivate;
	this.activate = particle_activate;
	this.isActive = particle_isActive;
}

// ----------------------------------------------
// -- Particle System
// ----------------------------------------------
function particlesystem_init()
{
	for (var i = 0; i < this.MAXPARTICLECOUNT; i++)
	{
		this.particles[i] = new particle();
	}
}

function particlesystem_deactivate()
{
	for (var i = 0; i < this.MAXPARTICLECOUNT; i++)
	{
		this.particles[i].deactivate();
	}
}

function particlesystem()
{
	this.MAXPARTICLECOUNT = 10;
	this.positionX = 0.0;
	this.positionY = 0.0;

	// -- Particle launch values. --
	// How long the particle can be alive.
	this.life = 0;

	// The angle the particle is emitted towards
	this.angle = 0;
	
	// The initial speed
	this.speed = 0.0;
	
	// The initial color
	this.r = 255;
	this.g = 0;
	this.b = 0;
	
	// The number of active particles
	this.count = 0;
	
	// The collection of particles
	this.particles = new Array(this.MAXPARTICLECOUNT);
}